<template>
  <div class="form-item">
    <el-input
      v-if="formItem.type === 'input'"
      v-model="modelValue"
      clearable
      @input="inputChange"
    ></el-input>
    <el-input-number
      style="width: 100%"
      v-model="modelValue"
      v-if="formItem.type === 'number'"
      clearable
      @change="inputChange"
    ></el-input-number>
    <el-select
      v-model="modelValue"
      placeholder=""
      clearable
      @change="inputChange"
      v-if="formItem.type === 'select'"
      style="width: 100%"
    >
      <el-option
        v-for="item in formItem.data"
        :key="item.dm"
        :label="item.mc"
        :value="item.dm"
      >
      </el-option>
    </el-select>
  </div>
</template>
<script>
export default {
  props: {
    value: [Object, Array, String, Number],
    formItem: Object
  },
  data () {
    return {
      modelValue: ''
    }
  },
  watch: {
    value (val) {
      this.modelValue = val
    }
  },
  mounted () {
    if (this.value) {
      this.modelValue = this.value
    }
  },
  methods: {
    /*
    抛出事件 
     */
    inputChange (val) {
      if (!val) {
        this.$emit('input', null)
        return
      }
      if (typeof val === 'object' && !Array.isArray(val)) {
        this.$emit('input', val.bm)
      } else {
        this.$emit('input', val)
      }
    }
  }
}
</script>
<style lang="scss" scoped></style>
